package cn.zqh.user.controller;



import cn.zqh.bean.api.CommonResult;
import cn.zqh.bean.bo.AdminChangeUserInfo;
import cn.zqh.bean.bo.UserChangeUserInfo;
import cn.zqh.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zqh
 * @since 2022-12-24
 */
@RestController
@RequestMapping("/user")
@Api("UserController")

public class UserController {

    @Autowired
    private UserService userService;

    /**
      * @Author: zqh
      * @Date:
      * @Description: 注册一个新用户
    */
    @ApiOperation(value = "创建一个新用户")
    @PostMapping("/createANewUser")
    public CommonResult createANewUser(String qq, String password,String Code){
        return userService.createANewUser(qq,password,Code);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 管理员修改用户信息
    */
    @ApiOperation(value = "管理员修改用户信息")
    @PostMapping("adminChangeInfo")
    public CommonResult adminChangeInfo(@RequestBody AdminChangeUserInfo adminChangeUserInfo){
        return userService.adminChangeInfo(adminChangeUserInfo);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改密码接口
    */
    @ApiOperation(value = "修改密码")
    @PostMapping("ChangePassword")
    public CommonResult changePassword(String userId,String password){
        return userService.changePassword(userId,password);
    }
    
    /**
      * @Author: zqh
      * @Date: 
      * @Description: 用户修改自己信息
    */
    @ApiOperation(value = "用户修改自己信息")
    @PostMapping("userChangeUserInfo")
    public CommonResult userCgOwnMation(@RequestBody UserChangeUserInfo userChangeUserInfo){
        return userService.userCgOwnMation(userChangeUserInfo);
    }

    /**
      * @Author: zqh
      * @Date: 
      * @Description: 通过用户id删除用户
    */
    @ApiOperation(value = "用户通过id删除用户")
    @DeleteMapping("delUserById")
    public CommonResult delUserById(String userId){
        return userService.delUserById(userId);
    }


    /**
      * @Author: zqh
      * @Date:
      * @Description: 查询已被禁用的账号
    */
    @ApiOperation(value = "查询已被禁用的账号")
    @GetMapping("getDelUser")
    public CommonResult getDelUser(Integer page,Integer size){
        return userService.getDelUser(page,size);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 根据用户id改表用户状态
    */
    @ApiOperation(value = "把被删除的用户取消删除")
    @PostMapping("CancelTheDeletedUser")
    public CommonResult cancelTheDeletedUser(String userId){
        return userService.cancelTheDeletedUser(userId);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 分页查询未被删除了的用户
    */
    @ApiOperation(value = "分页查询未被删除的用户")
    @GetMapping("/getAllUserByPage")
    public CommonResult getAllUserByPage(Integer page,Integer size){
        return userService.getAllUserByPage(page,size);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 通过邮箱查询用户拥有的权限
    */
    @ApiOperation("通过邮箱查询用户拥有的权限")
    @GetMapping("getUserPermission")
    public CommonResult getUserPermission(String email){
        return userService.getUserPermission(email);
    }


    /**
      * @Author: zqh
      * @Date:
      * @Description: 获取当前登录用户的信息
    */
    @ApiOperation("获取当前登录用户信息")
    @GetMapping("getLoginUserInfo")
    public CommonResult getLoginUserInfo(){
        return userService.getLoginUserInfo();
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 通过id查询某个用户信息
    */
    @ApiOperation("通过id查询某个用户信息")
    @GetMapping("getUserById")
    public CommonResult getUserById(String userId){
        return userService.getuserById(userId);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 获取所有用户的数量
    */
    @ApiOperation("获取所有用户的数量")
    @GetMapping("/getAllUserNumbers")
    public CommonResult getAllUserNumbers(){
        return userService.getAllUserNumbers();
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 管理员钱增加
    */
    @ApiOperation("管理员钱增加")
    @PostMapping("/addMoney")
    public CommonResult AdminUserAddMoney(Double money){
        return userService.AdminUserAddMoney(money);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 用户钱减少
    */
    @ApiOperation("用户钱减少")
    @PostMapping("/userReMoney")
    public CommonResult userReMoney(String userId,Double money){
        return userService.userReMoney(userId,money);
    }


    


}

